<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>申请提现-{$webname}</title>
    {Model_Supplier::css("style.css,base.css,extend.css",'brokerage')}
    {Common::js('jquery.min.js')}
    {Common::js('layer/layer.js')}

    <style>
        .error-txt {
            color: #333;
            display: inline-block;
            margin-left: 10px;
            font-size: 14px;
        }

        .error-txt:before {
            content: ' ';
            display: inline-block;
            width: 16px;
            height: 16px;
            vertical-align: middle;
            margin: -3px 5px 0 0;
            background: url(/plugins/supplier/public/default/pc/images/gys-dg-ico.png) no-repeat -52px -83px;
        }
    </style>
</head>
<body>
<div class="content-box">
    <div class="frame-box">
        <div class="finance-content">
            <form id="chkfrm">
                <div class="finance-bloock">
                    <div class="tixian-item">
                        <ul>
                            <li class="clearfix">
                                <strong class="item-bt">账户类型：</strong>
                                <div class="item-nr">
                                    <label id="bankcard" class="pay-way">
                                        <input type="radio" value="1" name="proceeds_type" {if $info['proceeds_type'] == 1} checked {/if} >银行卡</label>
                                    <label id="alipay" class="pay-way">
                                        <input type="radio" value="2" name="proceeds_type" {if $info['proceeds_type'] == 2} checked {/if} >支付宝</label>
                                    <label id="wechat" class="pay-way">
                                        <input type="radio" value="3" name="proceeds_type" {if $info['proceeds_type'] == 3} checked {/if} >微信</label>
                                </div>
                            </li>
                            <li class="clearfix bankcard-msg">
                                <strong class="item-bt">银行卡号：</strong>
                                <div class="item-nr">
                                    <input type="text" class="default-text w370" name="bankcardnumber" value="{$info['bankcardnumber']}">
                                    <span class="error-txt" style="display: none">请填写银行卡卡号</span>
                                </div>
                            </li>
                            <li class="clearfix bankcard-msg">
                                <strong class="item-bt">账户名：</strong>
                                <div class="item-nr">
                                    <input type="text" class="default-text w370" name="bankaccountname" value="{$info['bankaccountname']}">
                                    <span class="error-txt" style="display: none">请填写银行卡账户名</span>
                                </div>
                            </li>
                            <li class="clearfix bankcard-msg">
                                <strong class="item-bt">开户银行：</strong>
                                <div class="item-nr">
                                    <input type="text" class="default-text w370" name="bankname" value="{$info['bankname']}">
                                    <span class="error-txt" style="display: none">请填写开户行</span>
                                </div>
                            </li>
                            <li class="clearfix alipay-msg" style="display: none">
                                <strong class="item-bt">支付宝账号：</strong>
                                <div class="item-nr">
                                    <input type="text" class="default-text w370" name="alipayaccount" value="{$info['alipayaccount']}">
                                    <span class="error-txt" style="display: none">请填写正确的支付宝账户</span>
                                </div>
                            </li>
                            <li class="clearfix wechat-msg" style="display: none">
                                <strong class="item-bt">微信账号：</strong>
                                <div class="item-nr">
                                    <input type="text" class="default-text w370" name="wechataccount" value="{$info['wechataccount']}">
                                    <span class="error-txt" style="display: none">请填写正确的微信账户</span>
                                </div>
                            </li>
                            <li class="clearfix">
                                <strong class="item-bt">备注说明：</strong>
                                <div class="item-nr">
                                    <textarea class="bz-txt" style="resize: none"  name="description">{$info['description']}</textarea>
                                </div>
                            </li>
                            {if !empty($userinfo['mobile'])}
                            <li class="clearfix" >
                                <strong class="item-bt">手机号码：</strong>
                                <div class="item-nr"><span class="usable userphone">{$userinfo['mobile']}</span></div>
                            </li>

                            <li class="clearfix" >
                                <strong class="item-bt">验证码：</strong>
                                <div class="item-nr">
                                    <form id="setp2_form">
                                        <input type="text" class="default-text w200" name="smscode"  id="smscode" value="">
                                        <a class="yzm-btn sms-send" href="javascript:;" do-send="true">获取验证码</a>
                                    </form>
                                </div>
                            </li>
                            {/if}
                        </ul>
                    </div>
                    <div class="btn-block clearfix">
                        <input type="hidden" name="id" value="{$info['id']}">
                        <a class="tj-btn" href="javascript:;">保存</a>
                    </div>
                </div>
            </form>
        </div><!-- 申请提现 -->
    </div>
</div>


<div class="st-popup-box hide" style="border: 1px solid #dcdcdc;">
    <div class="st-tit"><strong>信息提示</strong><span class="closed"></span></div>
    <div class="st-conbox">
        <div class="txtcon">提现信息保存成功！</div>
        <div class="sure-btn"><a href="javascript:;" class="closed">确 定</a></div>
    </div>
</div>

{Common::js("jquery.validate.min.js")}
<script>
    $(function(){
        //打开页面时就选择到具体的栏目
        let proceeds_type = "{$info['proceeds_type']}";
        if(proceeds_type == 2){
            $(".alipay-msg").show();
            $(".bankcard-msg").hide();
            $(".wechat-msg").hide();
        }
        if(proceeds_type == 3){
            $(".wechat-msg").show();
            $(".alipay-msg").hide();
            $(".bankcard-msg").hide()
        }

        $("#alipay").on("click",function(){
            $(".alipay-msg").show();
            $(".bankcard-msg").hide();
            $(".wechat-msg").hide();
        });
        $("#bankcard").on("click",function(){
            $(".alipay-msg").hide();
            $(".wechat-msg").hide();
            $(".bankcard-msg").show()
        });
        $("#wechat").on("click",function(){
            $(".wechat-msg").show();
            $(".alipay-msg").hide();
            $(".bankcard-msg").hide()
        })
    })
</script>

<script>
    let SITEURL = "/supplier/";
    let is_allow = 1;

    $(function () {
        $('.hd-menu a').removeClass('cur');
        $('.hd-menu #brokerage').addClass('cur');
        $('#brokerage_approval').addClass('on');
        $("#withdrawamount").blur(function(){
            var amount = $(this).val();
            amount = Number(amount);
            amount = isNaN(amount) ? 0 : amount;
            $(this).val(amount);
        });
        $('.tj-btn').click(function () {
            let phone = $('.userphone').text();
            let smscode = $('#smscode').val();

            let promise = new Promise(function (resolve, reject) {

                if(phone != '')
                {
                    if(smscode != '')
                    {
                        $.post('/supplier_brokerage/ajax_smscode_validate', {
                            'newphone':  phone,
                            'smscode': smscode,
                        }, function (data) {
                            data.status == 1 ? resolve(data) :  reject(data);
                        }, 'json');
                    }
                    else
                    {
                        layer.msg('请填写验证码!',{icon:5,time:1000})
                        return false;
                    }
                }
                else
                {
                    resolve('phone');
                }

            })

            promise.then(function (res) {
                if(is_allow==0)
                {
                    layer.msg('请勿重复提交',{icon:5,time:1000})
                    return false;
                }
                var max = parseFloat($('#withdrawamount').attr('data-max'));
                var amount = parseFloat($('#withdrawamount').val());
                if(amount==0|| amount<0 ||amount>max)
                {
                    $('#withdrawamount').parent().find('.error-txt').show();
                    return false;
                }
                $('#withdrawamount').parent().find('.error-txt').hide();
                var proceeds_type = $('input[name=proceeds_type]:checked').val();
                if(proceeds_type==1)
                {
                    var bankcardnumber = $('input[name=bankcardnumber]').val();
                    var bankaccountname = $('input[name=bankaccountname]').val();
                    var bankname = $('input[name=bankname]').val();
                    if(bankcardnumber=='')
                    {
                        $('input[name=bankcardnumber]').parent().find('.error-txt').show();
                        return false;
                    }
                    else
                    {
                        $('input[name=bankcardnumber]').parent().find('.error-txt').hide();
                    }
                    if(bankaccountname=='')
                    {
                        $('input[name=bankaccountname]').parent().find('.error-txt').show();
                        return false;
                    }
                    else
                    {
                        $('input[name=bankaccountname]').parent().find('.error-txt').hide();
                    }
                    if(bankname=='')
                    {
                        $('input[name=bankname]').parent().find('.error-txt').show();
                        return false;
                    }
                    else
                    {
                        $('input[name=bankname]').parent().find('.error-txt').hide();
                    }

                }
                else if(proceeds_type==2)
                {
                    var alipayaccount = $('input[name=alipayaccount]').val();
                    if(alipayaccount=='')
                    {
                        $('input[name=alipayaccount]').parent().find('.error-txt').show();
                        return false;
                    }
                    else
                    {
                        $('input[name=alipayaccount]').parent().find('.error-txt').hide();
                    }
                }
                else
                {

                    var wechataccount = $('input[name=wechataccount]').val();
                    if(wechataccount=='')
                    {
                        $('input[name=wechataccount]').parent().find('.error-txt').show();
                        return false;
                    }
                    else
                    {
                        $('input[name=wechataccount]').parent().find('.error-txt').hide();
                    }
                }
                is_allow = 0 ;
                $.ajax({
                    dataType:'json',
                    type:'post',
                    data:$('#chkfrm').serialize(),
                    url:'/supplier_brokerage/ajax_save_approval_account',
                    success:function (data) {
                        if(data.status==1)
                        {
                            layer.msg('保存成功', {icon:4});
                        }
                        else
                        {
                            layer.msg('保存失败',{icon:5,time:1000})
                        }
                    }
                })

            }).catch(function (err) {
                layer.msg(err.msg, {icon:5});
            });


        })

        $('.closed').click(function () {
            location.reload();
        })

        function count_down(v) {
            if (v > 0) {
                $('.sms-send').html(--v  + '秒后重新发送');
                setTimeout(function () {
                    count_down(v);
                }, 1000);
                $('.sms-send').attr('do-send', 'false');
            }
            else {
                $('.sms-send').attr('do-send', 'true').html('重新发送');
            }
        }
        //验证码
        $('.sms-send').click(function () {
            $("#smscode").parent().find('.error-txt').hide();
            var bool = $(this).attr('do-send');
            var node = this;
            var userphone = $('.userphone').text();
            if (bool === 'true') {
                if (userphone != '') {
                    //发送验证码
                    $('.sms-send').attr('do-send', 'false');
                    $.post('/supplier/pc/pub/ajax_send_message', {'phone': userphone,'type':'findpass_code'}, function (bool) {
                        if (bool != 1) {
                            var message = bool == 0 ? '发送失败，请检查短信接口或消息开关' : bool;
                            $('.sms-send').attr('do-send', 'true');
                            layer.msg(message);
                        } else {
                            count_down(60);
                        }
                        return false;
                    }, 'text');
                }else{
                    layer.msg('新手机号格式错误', {icon:5});
                }
            }
        });
    });
</script>
</body>
</html>
